import { HTTP } from '../../../utils/http.js'
let ajax = new HTTP()
var app = getApp()

Page({
    data: {
        imgUrls: [],
        newsArr: [],
        placeType: 'news'
    },
    onLoad(options) {
        let memberid = app.globalData.memberid
        this._getSwiperList(memberid)
        this._getApplyList(memberid)
        wx.showLoading({
            title: '加载中',
        })
    },
    // 转发 
    onShareAppMessage: function () {

    },
    // 搜索跳转
    onSearchTap(event) {
        wx.navigateTo({
            url: '/pages/search/search?id=' + this.data.placeType,
        })
    },
    // 点击轮播
    onSwiperTap(event) {
        let id = event.detail.id
        wx.navigateTo({
            url: 'detail/detail?id=' + id
        })
    },
    // 文章跳转
    onNewsTap(event) {
        let newsId = event.currentTarget.dataset.articleid
        wx.navigateTo({
            url: 'detail/detail?id=' + newsId
        })
    },
    // 请求轮播数据
    _getSwiperList(memberid) {
        ajax.request({
            url: "articlelist/banner",
            data: {
                memberid: memberid
            },
            success: (res) => {
                this.setData({
                    imgUrls: res.data
                })
            }
        })
    },
    // 请求列表数据
    _getApplyList(memberid) {
        ajax.request({
            url: "articlelist",
            data: {
                memberid: memberid
            },
            success: (res) => {
                if (res.rescode === "0000") {
                    wx.hideLoading()
                    this.setData({
                        newsArr: res.data
                    })
                }
            }
        })
    }
})